package com.lhd.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lhd.mapper.SiteMapper;
import com.lhd.pojo.PageBean;
import com.lhd.pojo.PageCondition;
import com.lhd.pojo.Site;
import com.lhd.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SiteServiceImpl implements SiteService {
    @Autowired
    private SiteMapper siteMapper;
    @Override
    public List<Site> getAll() {
        return siteMapper.getAll();
    }

    @Override
    public PageBean<Site> getWithCondition(String name, Integer capacity, Integer curCapacity, String address, String phone, PageCondition pageCondition) {
        PageHelper.startPage(pageCondition.getPageNum(),pageCondition.getPageSize());
        Page<Site> page = siteMapper.getWithCondition(name, capacity, curCapacity, address, phone);
        long total = page.getTotal();
        List<Site> result = page.getResult();
        return new PageBean<>(total,result);
    }

    @Override
    public void updateSite(Site site) {
        siteMapper.updateSite(site);
    }

    @Override
    public void remove(Integer id) {
        siteMapper.remove(id);
    }

    @Override
    public void add(Site site) {
        siteMapper.add(site);
    }

}
